package com.soikc.kuaidiE.filter;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebFilter(urlPatterns = {"/express/*","/api/user/*","/admin/index.html","/admin/views"})
public class AssessControlFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse res = (HttpServletResponse) response;
        HttpSession session = req.getSession();
        Object userName = session.getAttribute("adminUserName");
        if (userName!=null){
            chain.doFilter(req, res);
        }else {
            res.sendError(403,"很遗憾，权限不足");
        }
    }
}
